package com.health.fragment.focusgroup;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.health.NovaApplication;
import com.health.PersonalFileActivity.onFragmentSave;
import com.health.R;
import com.health.adapter.CheckBoxAdapter;
import com.health.adapter.RadioButtonAdapter;
import com.health.db.FDbManager;
import com.health.focusgroup.JSJBctivity;
import com.health.fragment.NovaFragment;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.BD_DD_INFO;
import com.health.tablebean.CD_MENTALDISEASE_BASEINFO;
import com.health.tools.GlobalConts;
import com.health.tools.IDCardVerifyTool;
import com.health.view.spinner.NiceSpinner;
import com.health.widget.EditTextWithDate;
import com.health.widget.MyGridView;

import android.app.AlertDialog;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

/**
 * 重点人群-- 精神疾病---随访
 *
 */
public class JSJB_BaseFragment extends NovaFragment implements onFragmentSave {
	private static final String TAG = "JSJB_BaseFragment";
	private View cqsf2View = null;
	private FDbManager fdbmanger = null;

	// ------------------------------基本信息-----------------------------
	private EditText ed_xm;
	private EditText ed_jhr_name;
	private EditText ed_jhr_idcard;
	private EditText ed_jhr_address;
	private EditText ed_jhr_phone;
	private EditText ed_jwhlxr;
	private EditText ed_jwh_phone;
	private EditText ed_jhr_qz;

	private NiceSpinner nice_spinner_yhzgx;
	private NiceSpinner nice_spinner_zqty;
	private NiceSpinner nice_spinner_mz;
	private NiceSpinner nice_spinner_qkzd;
	private NiceSpinner nice_spinner_zjyczljg;
	private NiceSpinner nice_spinner_gszk;// 关锁状况
	private NiceSpinner nice_spinner_jjzk;// 经济状况
	private MyGridView gd_zlqk;

	private EditTextWithDate ed_qztime;
	private EditTextWithDate ed_csfbtime;
	private EditTextWithDate ed_scjsbyzsj;
	private EditTextWithDate ed_qzrq;
	private EditText ed_zy_cs;
	private EditText ed_qzyy;

	private EditText ed_sh_qdzs;
	private EditText ed_sh_zs;
	private EditText ed_sh_zh;
	private EditText ed_sh_zs4;
	private EditText ed_sh_zsws;
	private EditText ed_zkysyj;
	private EditText ed_sh_qtwhxw;
	private NiceSpinner ed_ysqm;// 医生签名
	private EditTextWithDate ed_tbsj;
	// ----------------------------------------------------------------------
	private RadioButtonAdapter adapter_ywblfy = null;
	private RadioButtonAdapter adapter_dyxysfjr = null;
	private RadioButtonAdapter adapter_xlsc = null;
	private RadioButtonAdapter adapter_xjbsfwj = null;
	private RadioButtonAdapter adapter_zzgy = null;

	private CheckBoxAdapter adapter_zz = null;

	private List<BD_DD_INFO> yhzgx_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> zqty_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> mz_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> qkzd_list = new ArrayList<BD_DD_INFO>();

	private List<BD_DD_INFO> zjyczljg_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> gszk_list = new ArrayList<BD_DD_INFO>();
	private List<BD_DD_INFO> jjzk_list = new ArrayList<BD_DD_INFO>();

	public ARCHIVE_BASEINFO userInfo;
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
	private int from_followup = -1;
	private String str_zzContent = "";
	private String str_zzId = "";
	private CheckBox cb_nothing;

	private RadioButton rb_cz;
	private RadioButton rb_nc;

	private RadioButton rb_zggr;
	private RadioButton rb_zgglz;
	private RadioButton rb_nm;
	private RadioButton rb_xghwy;
	private RadioButton rb_zxxs;
	private RadioButton rb_tx;
	private RadioButton rb_zyjsry;
	private RadioButton rb_qt;
	private RadioButton rb_bx;

	@Override
	public View findViews(LayoutInflater inflater) {
		fdbmanger = NovaApplication.fdbmanger;
		userInfo = NovaApplication.getUserInfo();
		cqsf2View = inflater.inflate(R.layout.jsjb_baseinfo, null);
		initViews(cqsf2View);
		GlobalConts.setMaxLength(25, ed_xm, ed_jhr_name, ed_jwhlxr, ed_jhr_qz);
		GlobalConts.setMaxLength(20, ed_jhr_phone, ed_jwh_phone);
		GlobalConts.setMaxLength(35, ed_jhr_address, ed_qzyy);
		GlobalConts.setMaxLength(5, ed_zy_cs);
		GlobalConts.setMaxLength(100, ed_zkysyj);
		return cqsf2View;
	}

	/**
	 * 初始化布局
	 * 
	 * @param v
	 * @author 王婷婷
	 * @date 2015年12月21日 上午11:10:55
	 */
	private void initViews(View v) {

		ed_xm = (EditText) v.findViewById(R.id.ed_xm);
		ed_jhr_name = (EditText) v.findViewById(R.id.ed_jhr_name);
		ed_jhr_idcard = (EditText) v.findViewById(R.id.ed_jhr_idcard);
		ed_jhr_address = (EditText) v.findViewById(R.id.ed_jhr_address);
		ed_jhr_phone = (EditText) v.findViewById(R.id.ed_jhr_phone);
		ed_jwhlxr = (EditText) v.findViewById(R.id.ed_jwhlxr);
		ed_jwh_phone = (EditText) v.findViewById(R.id.ed_jwh_phone);
		ed_jhr_qz = (EditText) v.findViewById(R.id.ed_jhr_qz);

		nice_spinner_yhzgx = (NiceSpinner) v.findViewById(R.id.nice_spinner_yhzgx);
		nice_spinner_zqty = (NiceSpinner) v.findViewById(R.id.nice_spinner_zqty);
		nice_spinner_mz = (NiceSpinner) v.findViewById(R.id.nice_spinner_mz);
		nice_spinner_qkzd = (NiceSpinner) v.findViewById(R.id.nice_spinner_qkzd);
		nice_spinner_zjyczljg = (NiceSpinner) v.findViewById(R.id.nice_spinner_zjyczljg);
		nice_spinner_gszk = (NiceSpinner) v.findViewById(R.id.nice_spinner_gszk);
		nice_spinner_jjzk = (NiceSpinner) v.findViewById(R.id.nice_spinner_jjzk);
		gd_zlqk = (MyGridView) v.findViewById(R.id.gd_zlqk);

		ed_qztime = (EditTextWithDate) v.findViewById(R.id.ed_qztime);
		ed_csfbtime = (EditTextWithDate) v.findViewById(R.id.ed_csfbtime);
		ed_scjsbyzsj = (EditTextWithDate) v.findViewById(R.id.ed_scjsbyzsj);
		ed_qzrq = (EditTextWithDate) v.findViewById(R.id.ed_qzrq);
		ed_zy_cs = (EditText) v.findViewById(R.id.ed_zy_cs);
		ed_qzyy = (EditText) v.findViewById(R.id.ed_qzyy);
		cb_nothing = (CheckBox) v.findViewById(R.id.cb_nothing);
		ed_sh_qdzs = (EditText) v.findViewById(R.id.ed_sh_qdzs);
		ed_sh_zs = (EditText) v.findViewById(R.id.ed_sh_zs);
		ed_sh_zh = (EditText) v.findViewById(R.id.ed_sh_zh);
		ed_sh_zs4 = (EditText) v.findViewById(R.id.ed_sh_zs4);
		ed_sh_zsws = (EditText) v.findViewById(R.id.ed_sh_zsws);
		ed_sh_qtwhxw = (EditText) v.findViewById(R.id.ed_sh_qtwhxw);
		ed_zkysyj = (EditText) v.findViewById(R.id.ed_zkysyj);
		ed_ysqm = (NiceSpinner) v.findViewById(R.id.ed_ysqm);
		ed_tbsj = (EditTextWithDate) v.findViewById(R.id.ed_tbsj);
		ed_tbsj.setBefore(true);
		ed_qzrq.setBefore(true);
		ed_csfbtime.setBefore(true);
		ed_scjsbyzsj.setBefore(true);
		ed_qztime.setBefore(true);

		rb_cz = (RadioButton) v.findViewById(R.id.rb_cz);
		rb_nc = (RadioButton) v.findViewById(R.id.rb_nc);

		rb_zggr = (RadioButton) v.findViewById(R.id.rb_zggr);
		rb_zgglz = (RadioButton) v.findViewById(R.id.rb_zgglz);
		rb_nm = (RadioButton) v.findViewById(R.id.rb_nm);
		rb_xghwy = (RadioButton) v.findViewById(R.id.rb_xghwy);
		rb_zxxs = (RadioButton) v.findViewById(R.id.rb_zxxs);
		rb_tx = (RadioButton) v.findViewById(R.id.rb_tx);
		rb_zyjsry = (RadioButton) v.findViewById(R.id.rb_zyjsry);
		rb_qt = (RadioButton) v.findViewById(R.id.rb_qt);
		rb_bx = (RadioButton) v.findViewById(R.id.rb_bx);
	}

	/**
	 * 绑定数据值
	 * 
	 * @param str_where
	 * @param flag
	 * @author 王婷婷
	 * @date 2015年12月17日 上午10:30:30
	 */
	private void bindDdata(String flag, String str_where) {
		List<BD_DD_INFO> listZZs = fdbmanger.findAllByWhereInInfoDB(BD_DD_INFO.class, str_where);

		if (flag.equals("症状")) {

			adapter_zz = new CheckBoxAdapter(getActivity(), listZZs);
			adapter_zz.setOtherMaxLength(50);
			gd_zlqk.setAdapter(adapter_zz);
		}
	}

	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {
		ed_jhr_idcard.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				String idNo = ed_jhr_idcard.getText().toString();
				String idCard18 = null;
				if (idNo.length() == 15) {
					if (IDCardVerifyTool.Validate(idNo).equals("")) {
						idCard18 = IDCardVerifyTool.from15to18(19, idNo);
					}
				} else if (idNo.length() == 18) {
					idCard18 = idNo;
				}
				if (idCard18 != null && idCard18.length() == 18) {
					if (IDCardVerifyTool.Validate(idNo).equals("")) {

					} else {
						new AlertDialog.Builder(getActivity()).setTitle("温馨提示").setMessage("您输入的身份证号码有误，请重新输入！")
								.setPositiveButton("确定", null).show();
					}
				}

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {
			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});

		cb_nothing.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					ed_sh_qdzs.setText("");
					ed_sh_qdzs.setFocusable(false);
					ed_sh_qdzs.setFocusableInTouchMode(false);

					ed_sh_zs.setText("");
					ed_sh_zs.setFocusable(false);
					ed_sh_zs.setFocusableInTouchMode(false);

					ed_sh_zh.setText("");
					ed_sh_zh.setFocusable(false);
					ed_sh_zh.setFocusableInTouchMode(false);

					ed_sh_zs4.setText("");
					ed_sh_zs4.setFocusable(false);
					ed_sh_zs4.setFocusableInTouchMode(false);

					ed_sh_zsws.setText("");
					ed_sh_zsws.setFocusable(false);
					ed_sh_zsws.setFocusableInTouchMode(false);
					
					ed_sh_qtwhxw.setText("");
					ed_sh_qtwhxw.setFocusable(false);
					ed_sh_qtwhxw.setFocusableInTouchMode(false);
				} else {
					ed_sh_qdzs.setFocusable(true);
					ed_sh_qdzs.setFocusableInTouchMode(true);

					ed_sh_zs.setFocusable(true);
					ed_sh_zs.setFocusableInTouchMode(true);

					ed_sh_zh.setFocusable(true);
					ed_sh_zh.setFocusableInTouchMode(true);

					ed_sh_zs4.setFocusable(true);
					ed_sh_zs4.setFocusableInTouchMode(true);

					ed_sh_zsws.setFocusable(true);
					ed_sh_zsws.setFocusableInTouchMode(true);
					
					ed_sh_qtwhxw.setFocusable(true);
					ed_sh_qtwhxw.setFocusableInTouchMode(true);
				}
			}
		});

	}

	@Override
	public void setData() {
		GlobalConts.doctorList(ed_ysqm);
		bindDdata("症状", "PARENTID='DM07-01'");

		bindSpinner("与患者关系", "PARENTID='DM01-06'");

		bindSpinner("门诊", "PARENTID='DM01-79'");
		bindSpinner("知情同意", "PARENTID='DM01-78'");
		bindSpinner("经济情况", "PARENTID='DM01-80'");
		bindSpinner("关锁情况", "PARENTID='DM01-75'");
		bindSpinner("最后一次治疗效果", "PARENTID='DM01-77'");
		bindSpinner("情况诊断", "PARENTID='DM07-04'");

		setData_BaseInfo();
	}

	@Override
	public void save() {
		setCheckPhoneNum();

	}

	/**
	 * 设置下拉
	 * 
	 * @param flagName
	 * @param strSql
	 * @author 王婷婷
	 * @date 2015年12月24日 上午9:19:28
	 */

	private void bindSpinner(String flagName, String strSql) {
		List<BD_DD_INFO> sList = FDbManager.getInstance(getActivity()).findAllByWhereInInfoDB(BD_DD_INFO.class, strSql);
		if (flagName.equals("与患者关系")) {
			// nice_adapter_pf = new NiceSpinnerAdapter<>(getActivity(), sList);
			// nice_spinner_pf.setAdapter(nice_adapter_pf);
			yhzgx_list = sList;
			nice_spinner_yhzgx.attachDataSource(yhzgx_list);

		} else if (flagName.equals("门诊")) {
			mz_list = sList;
			// nice_adapter_gm = new NiceSpinnerAdapter<>(getActivity(), sList);
			nice_spinner_mz.attachDataSource(mz_list);

		} else if (flagName.equals("知情同意")) {
			zqty_list = sList;
			// nice_adapter_gm = new NiceSpinnerAdapter<>(getActivity(), sList);
			nice_spinner_zqty.attachDataSource(zqty_list);

		} else if (flagName.equals("经济情况")) {
			jjzk_list = sList;
			nice_spinner_jjzk.attachDataSource(jjzk_list);

		} else if (flagName.equals("关锁情况")) {
			gszk_list = sList;
			nice_spinner_gszk.attachDataSource(gszk_list);
		} else if (flagName.equals("最后一次治疗效果")) {
			zjyczljg_list = sList;
			List<BD_DD_INFO> list = fdbmanger.findAllInInfoDB(BD_DD_INFO.class);
			for (int i = 0; i < list.size(); i++) {
				String str_id = list.get(i).getID();
				if (str_id.equals("DM01-69_5")) {
					zjyczljg_list.add(list.get(i));
				}
			}
			nice_spinner_zjyczljg.attachDataSource(zjyczljg_list);
		} else if (flagName.equals("情况诊断")) {
			qkzd_list = sList;
			nice_spinner_qkzd.attachDataSource(qkzd_list);
		}

	}

	/**
	 * 获取 被选中的checkbox
	 * 
	 * @author 王婷婷
	 * @date 2015年12月19日 上午11:34:30
	 */
	private void getCheckBoxedData() {

		str_zzId = adapter_zz.getCheckedIdsStr();
		str_zzContent = adapter_zz.getOther();

	}

	/**
	 * 保存数据
	 * 
	 * @author 王婷婷
	 * @date 2015年12月17日 上午11:13:39
	 */
	private void saveData_BaseInfo() {

		CD_MENTALDISEASE_BASEINFO ques = new CD_MENTALDISEASE_BASEINFO();

		ques.setIDCARD(userInfo.getIDCARD());
		// ques.setARCHIVEID(userInfo.getARCHIVEID());// 设置档案编号
		ques.setARCHIVEID("");
		ques.setLOCK_INFO(gszk_list.get(nice_spinner_gszk.getSelectedIndex()).getID());
		ques.setVILLAGE_TEL(ed_jwh_phone.getText().toString());
		ques.setSPECIALIST_PROPOSAL(ed_zkysyj.getText().toString());
		String str_ed_time1_start = ed_tbsj.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time1_start)) {
			try {
				ques.setFILLFORM_TIME((Date) dateFormat.parse(str_ed_time1_start));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		ques.setDOCTOR_MARK(NovaApplication.getDoctorList().get(ed_ysqm.getSelectedIndex()).getUSER_ID());
		ques.setCURRENT_UNIT(userInfo.getCREATEORG());

		ques.setIS_DEL("N");

		String str_ed_time_next = ed_scjsbyzsj.getText().toString();
		if (!TextUtils.isEmpty(str_ed_time_next)) {
			try {
				ques.setFIRST_TREATMENT_TIME((Date) dateFormat.parse(str_ed_time_next));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		// 1轻度滋事

		ques.setMILD_TROUBLE_FREQUEN(ed_sh_qdzs.getText().toString());
		// 2肇事

		ques.setCREATE_DISTU_FREQUEN(ed_sh_zs.getText().toString());

		// 3肇祸

		ques.setCAUSE_ACCID_FREQUEN(ed_sh_zh.getText().toString());

		// 4自伤

		ques.setAUTOLESION_FREQUEN(ed_sh_zs4.getText().toString());

		// 5自杀未遂

		ques.setATTEMPT_SUIC_FREQUEN(ed_sh_zsws.getText().toString());
		
		// 6其他危害行为
		ques.setOtherDamage_FREQUEN(Integer.valueOf(ed_sh_qtwhxw.getText().toString()));

		if (cb_nothing.isChecked()) {
			ques.setATTEMPT_SUICIDE_NONE("null");
		} else {
			ques.setATTEMPT_SUICIDE_NONE("");
		}

		ques.setGUARDIAN_ARCHIVEID(ed_jhr_idcard.getText().toString());
		ques.setGUARDIAN_NAME(ed_jhr_name.getText().toString());
		ques.setRALATION(yhzgx_list.get(nice_spinner_yhzgx.getSelectedIndex()).getID());
		ques.setGURADIAN_ADDR(ed_jhr_address.getText().toString());
		ques.setGURADIAN_PHONE(ed_jhr_phone.getText().toString());

		String str_ed_ccfbtime = ed_csfbtime.getText().toString();
		if (!TextUtils.isEmpty(str_ed_ccfbtime)) {
			try {
				ques.setFIRST_TIME((Date) dateFormat.parse(str_ed_ccfbtime));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		ques.setAGREE_MANAGEMENT(zqty_list.get(nice_spinner_zqty.getSelectedIndex()).getID());
		ques.setAGREE_SIGNATURE(ed_jhr_qz.getText().toString());

		String str_ed_agreetime = ed_qztime.getText().toString();
		if (!TextUtils.isEmpty(str_ed_agreetime)) {
			try {
				ques.setAGREE_TIME((Date) dateFormat.parse(str_ed_agreetime));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		ques.setSYMPTOM(str_zzId);
		ques.setSYMPTOM_OTHER(str_zzContent);

		ques.setOUTPATIEN(mz_list.get(nice_spinner_mz.getSelectedIndex()).getID());

		if (!TextUtils.isEmpty(ed_zy_cs.getText().toString())) {

			ques.setHOSPITAL_COUNT(ed_zy_cs.getText().toString());
		}

		ques.setDIAGNOSIS_INFO(qkzd_list.get(nice_spinner_qkzd.getSelectedIndex()).getID());
		ques.setDIAGNOSIS_HOSPITAL(ed_qzyy.getText().toString());

		String str_ed_qztime = ed_qzrq.getText().toString();
		if (!TextUtils.isEmpty(str_ed_qztime)) {
			try {
				ques.setDIAGNOSIS_TIME((Date) dateFormat.parse(str_ed_qztime));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		ques.setLAST_CURE(zjyczljg_list.get(nice_spinner_zjyczljg.getSelectedIndex()).getID());
		ques.setVILLAGE_CONTACTS(ed_jwhlxr.getText().toString());
		ques.setECONOMY(jjzk_list.get(nice_spinner_jjzk.getSelectedIndex()).getID());
		ques.setLAST_UPDATE_DATE(new Date());
		ques.setLAST_UPDATE_BY(NovaApplication.getDoctorList().get(ed_ysqm.getSelectedIndex()).getUSER_ID());
		
		if (rb_cz.isChecked()) {
			ques.setHousehold("DM01-26_1");
		}else if (rb_nc.isChecked()) {
			ques.setHousehold("DM01-26_2");
		}else{
			ques.setHousehold("");
		}
		
		//把就业情况数据保存在数据库中
		if (rb_zggr.isChecked()) {
			ques.setJYQK("1");
		}else if (rb_zgglz.isChecked()) {
			ques.setJYQK("2");
		}else if (rb_nm.isChecked()) {
			ques.setJYQK("3");
		}else if (rb_xghwy.isChecked()) {
			ques.setJYQK("4");
		}else if (rb_zxxs.isChecked()) {
			ques.setJYQK("5");
		}else if (rb_tx.isChecked()) {
			ques.setJYQK("6");
		}else if (rb_zyjsry.isChecked()) {
			ques.setJYQK("7");
		}else if (rb_qt.isChecked()) {
			ques.setJYQK("8");
		}else if (rb_bx.isChecked()) {
			ques.setJYQK("9");
		}else {
			
		}
		
		
		if (from_followup == 1) {

			ques.setUPDATEORG(userInfo.getCREATEORG());

			ques.setMODIFIED(NovaApplication.getDoctorList().get(ed_ysqm.getSelectedIndex()).getUSER_ID());
			fdbmanger.updata(ques, "IDCARD='" + userInfo.getIDCARD() + "'");
		} else {
			ques.setCREATED_DATE(new Date());
			ques.setCREATE_UNIT(userInfo.getCREATEORG());
			ques.setCREATEORG(userInfo.getCREATEORG());
			ques.setCREATED_BY(userInfo.getCREATED_BY());
			ques.setCREATER(userInfo.getCREATER());
			fdbmanger.save(ques);
			from_followup = 1;
		}
		((JSJBctivity) getActivity()).showTextDialog("保存成功");
	}

	/**
	 * 设置 显示followup
	 * 
	 * @author 王婷婷
	 * @date 2015年12月24日 下午2:25:11
	 */
	private void setData_BaseInfo() {
		List<CD_MENTALDISEASE_BASEINFO> queses = fdbmanger.findAllByWhere(CD_MENTALDISEASE_BASEINFO.class,
				"IDCARD='" + userInfo.getIDCARD() + "'");
		int size = queses.size();
		if (size > 0) {
			from_followup = 1;

			ed_xm.setText(userInfo.getCUSTOMERNAME());

			CD_MENTALDISEASE_BASEINFO ques1 = queses.get(0);
			nice_spinner_gszk.setSelectedIndex(getListIndex(ques1.getLOCK_INFO(), gszk_list));
			str_zzId = ques1.getSYMPTOM();
			adapter_zz.setChecked(str_zzId);
			str_zzContent = ques1.getSYMPTOM_OTHER();
			adapter_zz.setOther(str_zzContent);

			ed_jwh_phone.setText(ques1.getVILLAGE_TEL());
			ed_zkysyj.setText(ques1.getSPECIALIST_PROPOSAL());
			if (ques1.getFILLFORM_TIME() != null) {
				try {
					ed_tbsj.setText(dateFormat.format(ques1.getFILLFORM_TIME()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (ques1.getDOCTOR_MARK().equals(NovaApplication.getDoctorList().get(i).getUSER_ID())) {
					ed_ysqm.setSelectedIndex(i);
				}

			}
			String str_ed_time_next = ed_scjsbyzsj.getText().toString();
			if (ques1.getFIRST_TREATMENT_TIME() != null) {
				try {
					ed_scjsbyzsj.setText(dateFormat.format(ques1.getFIRST_TREATMENT_TIME()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			ed_sh_qdzs.setText(String.valueOf(ques1.getMILD_TROUBLE_FREQUEN()));

			ed_sh_zs.setText(String.valueOf(ques1.getCREATE_DISTU_FREQUEN()));
			ed_sh_zh.setText(String.valueOf(ques1.getCAUSE_ACCID_FREQUEN()));
			ed_sh_zs4.setText(String.valueOf(ques1.getAUTOLESION_FREQUEN()));
			ed_sh_zsws.setText(String.valueOf(ques1.getATTEMPT_SUIC_FREQUEN()));
			ed_sh_qtwhxw.setText(String.valueOf(ques1.getOtherDamage_FREQUEN()));

			if ("null".equals(ques1.getATTEMPT_SUICIDE_NONE())) {
				cb_nothing.setChecked(true);
			} else if (TextUtils.isEmpty(ques1.getATTEMPT_SUICIDE_NONE())) {
				cb_nothing.setChecked(false);
			}

			ed_jhr_idcard.setText(ques1.getGUARDIAN_ARCHIVEID());
			ed_jhr_name.setText(ques1.getGUARDIAN_NAME());

			nice_spinner_yhzgx.setSelectedIndex(getListIndex(ques1.getRALATION(), yhzgx_list));

			ed_jhr_address.setText(ques1.getGURADIAN_ADDR());
			ed_jhr_phone.setText(ques1.getGURADIAN_PHONE());

			String str_ed_ccfbtime = ed_csfbtime.getText().toString();
			if (ques1.getFIRST_TIME() != null) {
				try {
					ed_csfbtime.setText(dateFormat.format(ques1.getFIRST_TIME()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			nice_spinner_zqty.setSelectedIndex(getListIndex(ques1.getAGREE_MANAGEMENT(), zqty_list));
			ed_jhr_qz.setText(ques1.getAGREE_SIGNATURE());

			String str_ed_agreetime = ed_qztime.getText().toString();
			if (ques1.getAGREE_TIME() != null) {
				try {
					ed_qztime.setText(dateFormat.format(ques1.getAGREE_TIME()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			nice_spinner_mz.setSelectedIndex(getListIndex(ques1.getOUTPATIEN(), mz_list));

			ed_zy_cs.setText(ques1.getHOSPITAL_COUNT());

			nice_spinner_qkzd.setSelectedIndex(getListIndex(ques1.getDIAGNOSIS_INFO(), qkzd_list));
			ed_qzyy.setText(ques1.getDIAGNOSIS_HOSPITAL());

			if (ques1.getDIAGNOSIS_TIME() != null) {
				try {
					ed_qzrq.setText(dateFormat.format(ques1.getDIAGNOSIS_TIME()));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			nice_spinner_zjyczljg.setSelectedIndex(getListIndex(ques1.getLAST_CURE(), zjyczljg_list));
			ed_jwhlxr.setText(ques1.getVILLAGE_CONTACTS());
			nice_spinner_jjzk.setSelectedIndex(getListIndex(ques1.getECONOMY(), jjzk_list));
			if (!TextUtils.isEmpty(ques1.getHousehold())) {
				if ("DM01-26_1".equals(ques1.getHousehold())) {
					rb_cz.setChecked(true);
				}else if ("DM01-26_2".equals(ques1.getHousehold())) {
					rb_nc.setChecked(true);
				}
			}
			
			//获取数据库中保存的就业情况值
			if (!TextUtils.isEmpty(ques1.getJYQK())) {
				if ("1".equals(ques1.getJYQK())) {
					rb_zggr.setChecked(true);
				}else if ("2".equals(ques1.getJYQK())) {
					rb_zgglz.setChecked(true);
				}else if ("3".equals(ques1.getJYQK())) {
					rb_nm.setChecked(true);
				}else if ("4".equals(ques1.getJYQK())) {
					rb_xghwy.setChecked(true);
				}else if ("5".equals(ques1.getJYQK())) {
					rb_zxxs.setChecked(true);
				}else if ("6".equals(ques1.getJYQK())) {
					rb_tx.setChecked(true);
				}else if ("7".equals(ques1.getJYQK())) {
					rb_zyjsry.setChecked(true);
				}else if ("8".equals(ques1.getJYQK())) {
					rb_qt.setChecked(true);
				}else if ("9".equals(ques1.getJYQK())) {
					rb_bx.setChecked(true);
				}
			}
		} else {
			from_followup = 0;

			ed_xm.setText(userInfo.getCUSTOMERNAME());
			ed_tbsj.setText(dateFormat.format(new Date()));
			for (int i = 0; i < NovaApplication.getDoctorList().size(); i++) {
				if (NovaApplication.getDoctorList().get(i).getUSER_ID().equals(userInfo.getCREATED_BY())) {
					ed_ysqm.setSelectedIndex(i);
				}

			}
		}
	}

	private int getListIndex(String str, List<BD_DD_INFO> bds) {
		if (str != null && !str.equals("")) {

			for (int i = 0; i < bds.size(); i++) {
				if (str.equals(bds.get(i).getID())) {
					return i;
				}
			}
		}
		return 0;
	}

	/**
	 * 验证电话号码
	 * 
	 * @author 王婷婷
	 * @date 2016年3月4日 上午11:24:09
	 */
	private void setCheckPhoneNum() {
		// 监护人姓名
		String str_ed_jhr_name = ed_jhr_name.getText().toString();
		if (TextUtils.isEmpty(str_ed_jhr_name)) {
			ed_jhr_name.setBackgroundColor(Color.YELLOW);
			((JSJBctivity) getActivity()).showTextDialog("请输入监护人姓名");
			return;
		} else {
			ed_jhr_name.setBackgroundColor(Color.WHITE);
		}
		// 与患者关系
		String str_id = yhzgx_list.get(nice_spinner_yhzgx.getSelectedIndex()).getID();
		Log.w(TAG, "与患者关系：" + str_id);
		if (TextUtils.isEmpty(str_id)) {
			nice_spinner_yhzgx.setBackgroundColor(Color.YELLOW);
			((JSJBctivity) getActivity()).showTextDialog("请选择与患者关系");
			return;
		} else {
			nice_spinner_yhzgx.setBackgroundColor(Color.WHITE);
		}
		// 监护人地址
		String str_ed_jhr_address = ed_jhr_address.getText().toString();
		if (TextUtils.isEmpty(str_ed_jhr_address)) {
			ed_jhr_address.setBackgroundColor(Color.YELLOW);
			((JSJBctivity) getActivity()).showTextDialog("请输入监护人地址");
			return;
		} else {
			ed_jhr_address.setBackgroundColor(Color.WHITE);
		}

		// 监护人电话
		String str_ed_jhr_phone = ed_jhr_phone.getText().toString();
		if (TextUtils.isEmpty(str_ed_jhr_phone)) {
			ed_jhr_phone.setBackgroundColor(Color.YELLOW);
			((JSJBctivity) getActivity()).showTextDialog("请输入监护人电话");
			return;
		} else {
			if (!GlobalConts.isPhoneNumberValid(str_ed_jhr_phone)) {
				ed_jhr_phone.setBackgroundColor(Color.YELLOW);
				((JSJBctivity) getActivity()).showTextDialog("请输入正确的监护人电话");
				return;
			}
			ed_jhr_phone.setBackgroundColor(Color.WHITE);
		}

		// 居委会 电话
		String str_ch_phone = ed_jwh_phone.getText().toString();
		if (!TextUtils.isEmpty(str_ch_phone)) {
			if (!GlobalConts.isPhoneNumberValid(str_ch_phone)) {
				ed_jwh_phone.setBackgroundColor(Color.YELLOW);
				((JSJBctivity) getActivity()).showTextDialog("请输入正确的居委会联系电话");
				return;
			} else {
				ed_jwh_phone.setBackgroundColor(Color.WHITE);
			}
		} else {
			ed_jwh_phone.setBackgroundColor(Color.WHITE);
		}

		// 既往主要症状
		String str_zz = adapter_zz.getCheckedIdsStr();
		if (TextUtils.isEmpty(str_zz)) {
			gd_zlqk.setBackgroundColor(Color.YELLOW);
			((JSJBctivity) getActivity()).showTextDialog("请选择既往主要症状");
			return;
		} else {
			gd_zlqk.setBackgroundColor(Color.WHITE);
		}
		// qkzd_list.get(nice_spinner_qkzd.getSelectedIndex()).getID()

		// 目前诊断情况
		String str_qkzd = qkzd_list.get(nice_spinner_qkzd.getSelectedIndex()).getID();
		Log.w(TAG, "请选择目前诊断情况诊断" + str_id);
		if (TextUtils.isEmpty(str_qkzd)) {
			nice_spinner_qkzd.setBackgroundColor(Color.YELLOW);
			((JSJBctivity) getActivity()).showTextDialog("请选择目前诊断情况诊断");
			return;
		} else {
			nice_spinner_qkzd.setBackgroundColor(Color.WHITE);
		}

		// 身份证号
		String idNo = ed_jhr_idcard.getText().toString();
		String idCard18 = null;
		if (idNo.length() == 15) {
			if (IDCardVerifyTool.Validate(idNo).equals("")) {
			} else {
				((JSJBctivity) getActivity()).showTextDialog("您输入的监护人身份证号码有误，请重新输入！");
				return;
			}
		} else if (idNo.length() == 18) {
			idCard18 = idNo;
			if (idCard18 != null && idCard18.length() == 18) {
				if (IDCardVerifyTool.Validate(idNo).equals("")) {

				} else {
					((JSJBctivity) getActivity()).showTextDialog("您输入的监护人身份证号码有误，请重新输入！");
					return;
				}
			}

		} else if (idNo.length() == 0) {

		} else {
			((JSJBctivity) getActivity()).showTextDialog("您输入的监护人身份证号码有误，请重新输入！");
			return;
		}

		getCheckBoxedData();
		saveData_BaseInfo();
	}
}
